package top.gangster.lunan.contractservice.controller.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.gangster.lunan.contractservice.entity.Contract;
import top.gangster.lunan.contractservice.entity.vo.ContractVo;
import top.gangster.lunan.contractservice.service.vo.ContractVoService;
import top.gangster.lunan.result.Result;

@RestController
@RequestMapping("/contractservice/vo")
public class ContractVoController {
	@Autowired
	ContractVoService voService;

	/**
	 * 根据合同id获取ContractVo
	 * @param id 合同id
	 * @return ContractVo
	 */
	@GetMapping("/{id}")
	public Result getVoByContractId(@PathVariable String id) {
		ContractVo vo = voService.getVoByContractId(id);
		return Result.ok().data("contractVo",vo);
	}

	/**
	 * 根据合同id集合获取ContractList
	 * @return ContractVoList
	 */
	@PostMapping("/ids")
	public Result getVoByContractIdList(@RequestBody List<String> ids) {
		System.out.println(ids);
		List<ContractVo> voList = voService.getVoByContractIdList(ids);
		return Result.ok().data("contractVoList",voList);
	}

	/**
	 * 根据合同对象获取ContractVo
	 * @param contract 合同对象
	 * @return ContractVo
	 */
	@PostMapping("/contract")
	public Result getVoByContract(@RequestBody Contract contract) {
		ContractVo vo = voService.getVoByContract(contract);
		return Result.ok().data("contractVo",vo);
	}

	/**
	 * 根据合同对象集合获取ContractVoList
	 * @param contractList 合同对象集合
	 * @return ContractVoList
	 */
	@PostMapping("/contracts")
	public Result getVoByContractList(@RequestBody List<Contract> contractList) {
		List<ContractVo> voList = voService.getVoByContractList(contractList);
		return Result.ok().data("contractVoList",voList);
	}

	/**
	 * 根据合同类型id查询所有合同vo
	 * @param typeId 合同类型Id
	 * @return 所有该类型的合同vo
	 */
	@GetMapping("/type/{typeId}")
	public Result getVoByType(@PathVariable Integer typeId) {
		List<ContractVo> contractVoList = voService.getVoByContractTypeId(typeId);
		return Result.ok().data("contractVoList",contractVoList);
	}

	/**
	 * 根据合同类型id分页查询vo对象
	 * @param typeId 合同类型id
	 * @param current 当前页
	 * @param limit 页大小
	 * @return 分页查询结果
	 */
	@GetMapping("/type/{typeId}/{current}/{limit}")
	public Result getVoByType(@PathVariable Integer typeId,@PathVariable Long current,@PathVariable Long limit) {
		Page<ContractVo> page = voService
				.getVoByContractTypeId(typeId, current, limit);
		return Result.ok().data("page",page);
	}

	/**
	 * 根据合同状态id查询所有合同vo
	 * @param stateId 合同状态id
	 * @return 所有该状态的合同vo
	 */
	@GetMapping("/state/{stateId}")
	public Result getVoByState(@PathVariable Integer stateId) {
		List<ContractVo> voList = voService.getVoByContractStateId(stateId);
		return Result.ok().data("contractVoList",voList);
	}

	/**
	 * 根据合同状态id分页查询vo对象
	 * @param stateId 合同状态id
	 * @param current 当前页
	 * @param limit 页大小
	 * @return 分页查询结果
	 */
	@GetMapping("/state/{stateId}/{current}/{limit}")
	public Result getVoByState(@PathVariable Integer stateId,@PathVariable Long current,@PathVariable Long limit) {
		Page<ContractVo> voPage = voService
				.getVoByContractStateId(stateId, current, limit);
		return Result.ok().data("page",voPage);
	}
}
